using System;
using System.Collections;
using System.Threading;
using System.Web;
using Sedna.Core;
using Sedna.Core.Controller;
using Sedna.Core.Controller.Common;
using Sedna.Core.Security;
using Sedna.UI.Access;
using log4net;

namespace Sedna.UI.Access
{
	/// <summary>
	/// used for login check. if login is failed, in which case the LoginException is thrown by 
	/// the corresponding action
	/// a request is redirected to a login page once again at the same time cleaning 
	/// the contents of username and password fields.
	/// This handler also swtiches on the login error message indication.
	/// </summary>
	public class ExceptionHandler : AbstractExceptionHandler
	{
        private IAuthenticator authenticator;
        private String exceptionPath;
	    public IAuthenticator Authenticator
	    {
	        set { authenticator = value; }
	    }

	    public string ExceptionPath
	    {
	        set { exceptionPath = value; }
	    }


		public override IActionResult HandleException(IExecutionContext executionContext, Exception exception)
		{
		    if(exception is SednaException)
		    {
		        executionContext.SetPropertyValue(exceptionPath, ((SednaException)exception).ExceptionCode);    
		    }
            else
		    {
		        executionContext.SetPropertyValue(exceptionPath, -1);
		    }
            executionContext.SetPropertyValue("ec['errorlabel2.visible']", true);
			return new ActionResult(successStatus);
		}
	}
}
